package TailRecursionLambda;

import java.util.stream.Stream;

public interface ITailRecursion<T> {
    ITailRecursion<T> apply();

    default Boolean isComplete() {
        return Boolean.FALSE;
    }

    default T getResult() {
        throw new RuntimeException("递归还没有结束，暂时得不到结果");
    }

    default T invoke() {
        return Stream.iterate(this, ITailRecursion::apply)
                .filter(ITailRecursion::isComplete)
                .findFirst()
                .get()//执行急方法
                .getResult();
    }
}
